package nlpir;

import java.io.File;

import com.sun.jna.Library;
import com.sun.jna.Native;

public class NLPIR_loaddiction {

	// 定义接口CLibrary，继承自com.sun.jna.Library
	public interface CLibrary extends Library {
		// 定义并初始化接口的静态变量
		CLibrary Instance = (CLibrary) Native.loadLibrary(
				new File("Fenci2014\\bin\\NLPIR").getAbsolutePath(), CLibrary.class);

		public int NLPIR_Init(String sDataPath, int encoding,
				String sLicenceCode);

		public String NLPIR_ParagraphProcess(String sSrc, int bPOSTagged);

		public String NLPIR_GetKeyWords(String sLine, int nMaxKeyLimit,
				boolean bWeightOut);

		public String NLPIR_GetFileKeyWords(String sLine, int nMaxKeyLimit,
				boolean bWeightOut);

		public int NLPIR_AddUserWord(String sWord);// add by qp 2008.11.10

		public int NLPIR_DelUsrWord(String sWord);// add by qp 2008.11.10

		public String NLPIR_GetLastErrorMsg();

		public int NLPIR_ImportUserDict(String sUserDict);

		public int NLPIR_SaveTheUsrDic();

		public void NLPIR_Exit();

	}

	public int load(String path) {
		File file=new File("Fenci2014");
		String pathStr=file.getAbsolutePath();
		// String system_charset = "GBK";//GBK----0
		String system_charset = "UTF-8";
		int charset_type = 1;
		int init_flag = CLibrary.Instance.NLPIR_Init(pathStr, charset_type, "0");
		String nativeBytes = null;
		if (0 == init_flag) {
			nativeBytes = CLibrary.Instance.NLPIR_GetLastErrorMsg();
			System.err.println("初始化失败！fail reason is " + nativeBytes);
		}
		
		int countNumber = CLibrary.Instance
				.NLPIR_ImportUserDict(path);
		
		int count = CLibrary.Instance.NLPIR_SaveTheUsrDic();
		
		return countNumber;
	}

}
